import pandas as pd

# 读取 CSV 文件
file_path = 'sales_data.csv'
data = pd.read_csv(file_path)

# 计算 DailySales 列
data['DailySales'] = data['Amount'] * data['Price']

# 保存修正后的数据到新的 CSV 文件
output_file_path = 'sales_data_with_daily_sales.csv'
data.to_csv(output_file_path, index=False)

print(f"\n修正后的数据已保存到文件：{output_file_path}")

# 月销售汇总字典
data['Date'] = pd.to_datetime(data['Date'])
monthly_sales = data.groupby(data['Date'].dt.to_period('M')).agg(Total_Sales=('DailySales', 'sum'))
monthly_sales_dict = monthly_sales['Total_Sales'].to_dict()

print("\n月销售汇总字典：")
print(monthly_sales_dict)

# 最畅销产品名称
product_sales = data.groupby('Product').agg(Total_Sales=('DailySales', 'sum'))
most_popular_product = product_sales['Total_Sales'].idxmax()

print(f"\n最畅销产品名称：{most_popular_product}")